/*
 * @Author: funlee
 * @Email: i@funlee.cn
 * @Date: 2019-06-27 10:30:21
 * @Description: 挖掘查询
 */
import { observable, action } from "mobx";
import resource from "@/utils/resource";
import API from "@/utils/api";

class ExcavateQueryStore {
    @observable keyWords = "";

    @observable filterType = ""; // 所属类型
    @observable filterAmount = ""; // 使用人数
    @observable filterTime = ""; // 运营时间
    @observable filterScore = ""; // 风险评分
    @observable filterArea = ""; // 所属区域

    @observable sortType = ""; // 按照什么排序

    @observable resultCurrentPage = 1; // 搜索结果页-列表分页

    @observable amountData = { all: 0, company: 0, person: 0 }; // 搜索主页三个总数统计
    @observable resultListData = { count: 0, lists: [] }; // 搜索结果页-列表
    @observable recentLlyData = []; // 最近查看 APP
    @observable hotData = []; // 热点查看 APP

    @observable detailId = ""; // 详情页目标对象的 id

    @action.bound
    getAmountData() {
        resource.get(API.excavatequeryAmount).then(res => {
            this.amountData = res;
        });
    }

    @action.bound
    changeKeyWords(keyWords) {
        this.keyWords = keyWords;
    }

    @action.bound
    setNature(type, value, isGetData) {
        this[type] = value;
        if (isGetData) {
            this.getResultListData();
        }
    }

    @action.bound
    getResultListData() {
        resource
            .get(API.excavatequerySearch, {
                page: this.resultCurrentPage,
                keyWords: this.keyWords
                // 添加各种参数
            })
            .then(res => {
                this.resultListData = res;
            });
    }

    @action.bound
    getRecentlyData() {
        resource.get(API.excavatequerySearchRecently).then(res => {
            this.recentLlyData = res;
        });
    }

    @action.bound
    getHotData() {
        resource.get(API.excavatequerySearchHot).then(res => {
            this.hotData = res;
        });
    }

    @action.bound
    setDetailId(id) {
        this.detailId = id;
    }

    @action.bound
    changePage(newPage) {
        this.currentPage = newPage;
        this.getResultListData();
    }
}

export default new ExcavateQueryStore();
